<%@ include file="/taglibs.jsp"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="${js}/jquery-1.6.min.js" type="text/javascript"></script>
<title></title>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.STYLE1 {font-size: 12px}
.STYLE4 {
	font-size: 12px;
	color: #1F4A65;
	font-weight: bold;
}

a:link {
	font-size: 12px;
	color: #06482a;
	text-decoration: none;

}
a:visited {
	font-size: 12px;
	color: #06482a;
	text-decoration: none;
}
a:hover {
	font-size: 12px;
	color: #FF0000;
	text-decoration: underline;
}
a:active {
	font-size: 12px;
	color: #FF0000;
	text-decoration: none;
}
.STYLE7 {font-size: 12}

-->
</style>

<script>
var yue = '${acct.account}';

var sendnum = 1;
function saveFunction()
{

	if($("#phone").val() == "")
	{
		alert('发送号码不能为空!');
		return false;
	}

	if($("#message").val() == "")
	{
		alert('短信内容不能为空');
		return false;
	}
	
	
	if(document.getElementById("isUse").checked == true){
		var s1 = $("#message").val();
		var s2 = $("#signname").val();
		var s = s1+s2;
		if(s.length > ${chanel.singlecount }){
			sendnum = 2;
		}else{
			sendnum = 1;
		}
		if(s.length > ${chanel.totalcount})
		{
			alert('短信内容长度不能超过${chanel.totalcount}字');
			return false;
		}
	}else{
		if($("#message").val().length > ${chanel.singlecount }){
			sendnum = 2;
		}else{
			sendnum = 1;
		}
		if($("#message").val().length > ${chanel.totalcount})
		{
			alert('短信内容长度不能超过${chanel.totalcount}字');
			return false;
		}
	}
	var ct = document.getElementById("numberCount").value;
	var tolc = ct * sendnum;
	if(tolc>yue){
		alert("余额不足");
		return ;
	}else{
		var url = "${ctx}/put/usernumsend";
		$('#sms-fms').attr('action',url);
		$('#sms-fms').submit();
	}  
}




function WordsCount(){
	if(document.getElementById("isUse").checked == true){
		var s1 = $("#message").val();
		var s2 = $("#signname").val();
		var s = s1+s2;
		$('#txtWordsCount').val(s.length);
	}else{
		var l = $('#message').val();
		$('#txtWordsCount').val(l.length);
	}
}
function ClearList(){
	$('#txtList').val("");
	$('#txtPhonesCount').val("0");
}
function ClearContent(){
	document.getElementById("message").value = "";
	//document.form1.txtSignature.value = "";
}
function myKeyDown()
{
    var k=window.event.keyCode; 
	if(event.ctrlKey){
		if ((k==67)||(k==99)||(k==86)||(k==118)||(k==88)||(k==120)) 
		{}
		else{
			window.event.returnValue = false;}
	}
	else{
    	if ((k==46)||(k==13)||(k==8)||(k>=48 && k<=57)||(k>=96 && k<=105)||(k>=37 && k<=40))  
     	{}
    	else {
        	window.event.returnValue = false;}	
	}
}
function PhonesCount(){
	var tmp1,tmp2,i,len,count;
	tmp1 = document.getElementById("phone").value;
	tmp2 = tmp1.split('\r\n');
	len=tmp2.length;
	count=0;
	for(i=0;i<len;i++){
		if(tmp2[i].length>0)
			count++;
	}
	document.getElementById("numberCount").value = count;
}

function DisabledOrNot(){
	var state = !document.form1.tmrSend.checked;
	document.getElementById("tmrYear").disabled = state;
	document.getElementById("tmrMonth").disabled = state;
	document.getElementById("tmrDay").disabled = state;
	document.getElementById("tmrHour").disabled = state;
	document.getElementById("tmrMinute").disabled = state;
}

function RemoveIrregular(){
	var tmp1,tmp2,i,len,count,list;
	var head=",134,135,136,137,138,139,147,150,151,152,157,158,159,181,182,183,184,187,188,130,131,132,155,156,185,186,133,153,180,189,";
	tmp1 = document.form1.txtList.value;
	tmp1 = tmp1.replace(/[^\r\n\d]/g,'');
	tmp2 = tmp1.split('\r\n');
	len=tmp2.length;
	count=0;
	list="";
	for(i=0;i<len;i++){
		if(tmp2[i].length>0){
			if(tmp2[i].length==11 && tmp2[i].charAt(0)=='1'){
				if (head.indexOf(tmp2[i].substring(0,3),0)>0){
					count++;
					list+=tmp2[i]+'\r\n';
				}
			}
			
			else if((tmp2[i].length==11||tmp2[i].length==12) && tmp2[i].charAt(0)=='0'){
					count++;
					list+=tmp2[i]+'\r\n';	
			}
			
		}
	}
	if(list.lastIndexOf('\r\n')>=0){
		list = list.substr(0,list.length-2);//去除最后的回车
	}
	document.form1.txtPhonesCount.value = count;	
	document.form1.txtList.value=list;
}
function RemoveSame(){
	var tmp1,tmp2,i,j,len,count,list;
	tmp1 = document.form1.txtList.value;
	tmp2 = tmp1.split('\r\n');
	len=tmp2.length;
	count=0;
	list="";
	for(i=0;i<len;i++){
		if(tmp2[i].length>0){
			for(j=i+1;j<len;j++){
				if(tmp2[i]==tmp2[j]){
					tmp2[j]="";
				}
			}
			count++;
			list+=tmp2[i]+'\r\n';
		}
	}
	if(list.lastIndexOf('\r\n')>=0){
		list = list.substr(0,list.length-2);//去除最后的回车
	}

	$('#txtPhonesCount').val(count);
	$('#txtList').val(list);
}

function onMessageKey()
{
	var l = $('#message').val().length;
	$('#txtWordsCount').val(l);
	
	if(l>${chanel.singlecount}){
		document.getElementById("tcounts").innerText="2条短信";
	}
}
function clsPhones()
{
	$('#phone').val('');
}

function moreMessage(){
	 var url = "${ctx}/moremessage/selmes";
	 var iWidth=500; //窗口宽度
          var iHeight=400;//窗口高度
          var iTop=(window.screen.height-iHeight)/2;
          var iLeft=(window.screen.width-iWidth)/2;
          window.open(url,"Detail","Scrollbars=no,Toolbar=no,Location=no,Direction=no,Resizeable=no,Width="+iWidth+" ,Height="+iHeight+",top="+iTop+",left="+iLeft);
}
function getCus(){
	  var url = "${ctx}/custemer/allcus";
 	  var iWidth=800; //窗口宽度
      var iHeight=400;//窗口高度
      var iTop=(window.screen.height-iHeight)/2;
      var iLeft=(window.screen.width-iWidth)/2;
      window.open(url,"Detail","Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no,Width="+iWidth+" ,Height="+iHeight+",top="+iTop+",left="+iLeft);
}

function uploadPhones(){
	  var url = "${ctx}/put/phone";
 	  var iWidth=400; //窗口宽度
      var iHeight=200;//窗口高度
      var iTop=(window.screen.height-iHeight)/2;
      var iLeft=(window.screen.width-iWidth)/2;
      window.open(url,"Detail","Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no,Width="+iWidth+" ,Height="+iHeight+",top="+iTop+",left="+iLeft);
}

function errorNum(){
	    if (document.getElementById("phone").value == ""){
	    	 PhonesCount();
	    	 return;
	    } 
	
	    var arrData=new Array();
	    var ObjM=document.getElementById("phone");
	    var mob=ObjM.value;
	    if (mob.length<9){
		    ObjM.value=""; 
		    PhonesCount();
		    return;
	    }
	    arrData=mob.match(/\d+/g);
	    if(arrData=="" || arrData==null){
		    ObjM.value="";
		    PhonesCount();
		    return;
	    }
    	
	    if (arrData.length>0)
	    {      
		    var j=0,u=0,t=0,m=0,n=0;
		    var arrDatam=new Array();
		    for (var i = 0; i < arrData.length; i++) {
			    if(isTel(arrData[i])){
				    //arrDatat[t]=arrData[i];
				    t++;
				    arrDatam[n]=arrData[i];
				    n++;
			    }
			    else if(isMobile(arrData[i])){
				    //arrDatam[m]=arrData[i];
				    m++;
				    arrDatam[n]=arrData[i];
				    n++;
			    } 
		    }
    		
		    re = /(\,)+/g;
    		  
		    var mobiles=arrDatam.join(',');//转换为字符串
		    mobiles=mobiles.replace(re,"\r\n");
		    document.getElementById("phone").value=mobiles;
	 		PhonesCount(); 
		}
}

function sameNum(){
	 	if (document.getElementById("phone").value == ""){
	 		 PhonesCount();
	 	 return;	
	 	}
           
	 
	    var arrData=new Array();
	    var ObjM=document.getElementById("phone");
	    var mob=ObjM.value;
	    if (mob.length<9){
		    ObjM.value="";
		     PhonesCount();
		    return;
	    }
	    arrData=mob.match(/\d{11}/g);
	    if(arrData=="" || arrData==null){
		    ObjM.value=""; 
		    PhonesCount();
		    return;
	    }
	    
	    if (arrData.length>0)
	    {      
		    var n=0;
		    var arrDatam=new Array();
		    var tels="";
		    for (var i = 0; i < arrData.length; i++) {
			    if(tels.indexOf(arrData[i]) == -1){
				    tels=tels+","+arrData[i];
				    arrDatam[n]=arrData[i]; 
				    n++;
			    }
		    }
		    re = /(\,)+/g;  
		    var mobiles=arrDatam.join(',');//转换为字符串
		    mobiles=mobiles.replace(re,"\r\n");
		    document.getElementById("phone").value=mobiles;
		    PhonesCount();
		 }
}
 	function isTel(value) {
	    if (/^0(([1,2]\d)|([3-9]\d{2}))\d{8}$/g.test(value) ){
		    return true;
	    }
	    else {
		    return false;
	    }
    }
 function isCUMobile(value) {
	    if (/^13[0|1|2]\d{8}$/g.test(value)  || (/^145\d{8}$/g.test(value)) || (/^15[4|5|6]\d{8}$/g.test(value)) || (/^18[6|5]\d{8}$/g.test(value))) {
		    return true;
	    }
	    else {
		    return false;
	    }
    }
    function isCTMobile(value) {
	    if (/^133\d{8}$/g.test(value) || (/^153\d{8}$/g.test(value)) || (/^18[9|0]\d{8}$/g.test(value))) {
		    return true;
	    }
	    else {
		    return false;
	    }
    }
    function isCMMobile(value) {
	    if (/^13[4|5|6|7|8|9]\d{8}$/g.test(value) || (/^147\d{8}$/g.test(value)) || (/^15[0|1|2|7|8|9]\d{8}$/g.test(value)) || (/^18[1|2|3|7|8]\d{8}$/g.test(value))) {
		    return true;
	    }
	    else {
		    return false;
	    }
    }
   
     function isMobile(value) {
        if (/^13\d{9}$/g.test(value) || (/^14\d{9}$/g.test(value)) || (/^15\d{9}$/g.test(value)) || (/^16\d{9}$/g.test(value)) || (/^18\d{9}$/g.test(value))) {
            return true;
        }
        else {
            return false;
        }
    }
</script>
</head>
<body>
<form id="sms-fms" method="post" enctype= "multipart/form-data" action="" name="">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="15" height="30"><img src="${img}/tab_03.gif" width="15" height="30" /></td>
        <td width="1101" background="${img}/tab_05.gif"><img src="${img}/311.gif" width="16" height="16" /> <span class="STYLE4">${title}</span></td>
        <td width="281" background="${img}/tab_05.gif"><table border="0" align="right" cellpadding="0" cellspacing="0">
        </table></td>
        <td width="14"><img src="${img}/tab_07.gif" width="14" height="30" /></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="9" background="${img}/tab_12.gif">&nbsp;</td>
        <td ><table width="100%" border="0.5" align="left" cellpadding="0" cellspacing="1" >
          <tr>
            <td width="100%" height="18" class="STYLE1">
           	 	 <table width="100%" align="left" border="0">
				 <tr height="20px">
						<td width="5%" align="right"></td>
						<td width="54%" align="center" style="font-size: 18px">短信条数:&nbsp;&nbsp;&nbsp;&nbsp;<font color="red"><B>${acct.account}</B>&nbsp;&nbsp;&nbsp;&nbsp;</font>条</td>
						<td width="32%" align="left"></td>
		        </tr>
				  <tr height="20px">
						<td width="5%" align="right">&nbsp;</td>
						<td width="54%">&nbsp;</td>
						<td width="32%" align="left" >&nbsp;</td>
		        </tr>
				 
				<tr>
				<td width="5%" align="right">短信内容</td>
				<td width="54%"><textarea name="message" style="border:1px solid #cccccc;width:600px;height:85px;" id="message" rows="5" onkeyup="onMessageKey();"></textarea></td>
				<td width="32%" align="left" >
							<font color="red" size="4px">每条短信${chanel.singlecount }个字符，最大输入${chanel.totalcount }个字</font>	</td>
  </tr>
  
  <tr>
				<td width="5%"></td><td colspan="2">字数：<input type='text' name='txtWordsCount' id="txtWordsCount" value='0' class='input' size='4' readonly>&nbsp;
							使用签名：<input type="checkbox" name="isUse" id="isUse" onclick="WordsCount();"/><input name="signname" id="signname" value="${userInfo.signName}" class='input' size='4' >  
						<input type="button" value="常用短信" onclick="moreMessage()"/>
					    <input type="button" class="button" value="清空内容" onClick="javascript:ClearContent();WordsCount();">&nbsp;&nbsp;&nbsp;&nbsp;<span id="tcounts">1条短信</span></td>
  </tr>
				<tr>
					<td  width="5%" align="right">
						 手机号码					</td>
					<td align="left" width="54%">
					  <textarea name="phone" id="phone" style="BORDER-BOTTOM: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; WIDTH: 600px; MARGIN-BOTTOM: 5px; HEIGHT: 85px; BORDER-TOP: #cccccc 1px solid; BORDER-RIGHT: #cccccc 1px solid" onblur="PhonesCount();"></textarea>				  </td>
				  <td align="left" width="32%">
					<font color="red" size="4px">每个号码以『回车键』结束</font>					</td>	
				</tr>
				<tr>
					<td align="right" width="15%">					</td>
					<td align="left" width="36%">
					号码数量：<input type='text' name='numberCount' id="numberCount" value='0' class='input' size='4' readonly>&nbsp;
					<input type="button" value="通讯录" onclick="getCus()"/>
				    <input type="button" value="过滤错号" onclick="errorNum()"/>
				    <input type="button" value="过滤重号" onclick="sameNum()"/>
				    <input type="button" class="button" value="清空号码" onClick="clsPhones();PhonesCount();">
				    <input type="button" class="button" value="上传号码" onClick="uploadPhones();">
				    </td>	
  </tr>
				 
			</table>
           	 	 
            </td>
          </tr>
        </table></td>
        <td width="9" background="${img}/tab_16.gif">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="29"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="15" height="29"><img src="${img}/tab_20.gif" width="15" height="29" /></td>
        <td background="${img}/tab_21.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr align="center">
            <td width="25%" height="29" nowrap="nowrap">
            <input type="button" name="sbt"  value="发送" onclick="saveFunction();"/>
           
          </tr>
        </table></td>
        <td width="14"><img src="${img}/tab_22.gif" width="14" height="29" /></td>
      </tr>
    </table></td>
  </tr>
</table>
</form>
</body>
</html>